import { Component, Input, OnInit } from '@angular/core';
import { HttpService } from "src/app/shared/service/http.service";
import { AppGlobalService } from "src/app/shared/service/app-global.service";
import { ModalController, AlertController } from "@ionic/angular";

@Component({
  selector: 'app-new-inquiry-page-modal',
  templateUrl: './new-inquiry-page-modal.component.html',
  styleUrls: ['./new-inquiry-page-modal.component.scss'],
})
export class NewInquiryPageModalComponent implements OnInit {

  @Input() tagData: any;
  constructor(
    private httpService: HttpService,
    public modalController: ModalController,
    private appGlobalService: AppGlobalService,
    public alertController: AlertController
  ) { }

  ngOnInit() {
    // for (let index = 0; index < 3; index++) {
    //   console.log(JSON.stringify(this.tagData));
    // }
  }

  closeClick() {
    this.modalController.dismiss({ back: true });
  }

  buttonClick(event, obj) {
    event.stopPropagation();
    try {
      // 有link直接跳转到page，
      if (obj.link) {
        try {
          if (obj.link.target) {
            const targetObj = { pageId: obj.link.target, params: obj.link.params, sessionId: localStorage.getItem('sessionId') };
            this.appGlobalService.goToForward(targetObj);
            this.modalController.dismiss({ back: false });
          }
        } catch (error) {
        }
      } else {
        const params = {
          content: obj.submit.content,
          id: obj.submit.id,
          sessionId: localStorage.getItem("sessionId")
        };
        this.httpService.post("application/submit", params, res => {
          if (res.success) {
            this.appGlobalService.showToast(res.message, 1000, "middle");
            this.modalController.dismiss({ back: false });
          } else {
            this.appGlobalService.showToast(res.message, 1000, "middle");
            this.modalController.dismiss({ back: false });
          }
        });
      }

    } catch (error) {
      console.log(JSON.stringify(error));
    }
  }


}
